tadvReplace = {

	init : function() {
		var c = document.getElementById('content');
		var se = ( 'undefined' != typeof switchEditors ) ? switchEditors : null;

		if ( se ) {
			se.pre_wpautop = tadvReplace.pre_format;
		}
	},

	pre_format : function(c) {
		c = c.replace(/<p>?\s?<\/p>/g, '<p>&nbsp;</p>'); // keep empty paragraphs...
		c = c.replace(/<\/p>/g, '</p>\n');
		c = c.replace(/\[\/sourcecode\]\s*<br \/>\s*<br \/>/g, '[/sourcecode]\n');
		c = c.replace(new RegExp('\\s*\\[caption([^\\[]+)\\[/caption\\]\\s*', 'gi'), '\n[caption$1[/caption]\n');
		c = c.replace(new RegExp('caption\\]\\n\\n+\\[caption', 'g'), 'caption]\n[caption');
		
		return tinymce.trim(c);
	}
	
}

if (typeof addLoadEvent == 'function') {
	addLoadEvent(function(){tadvReplace.init();});
}